﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Administration_Users_New : System.Web.UI.Page {

    protected void Page_Load(object sender, EventArgs e) {
        if (!this.IsPostBack) this.TextBoxPassword.Text = Membership.GeneratePassword(Membership.MinRequiredPasswordLength, Membership.MinRequiredNonAlphanumericCharacters);
    }

    protected void ButtonSubmit_Click(object sender, EventArgs e) {
        if (!this.IsValid) return;

        MembershipCreateStatus status;
        var user = Membership.CreateUser(this.TextBoxUserName.Text, this.TextBoxPassword.Text, this.TextBoxEmail.Text, null, null, true, out status);

        if (status == MembershipCreateStatus.Success) {
            user.Comment = this.TextBoxFullName.Text;
            Membership.UpdateUser(user);
            Response.Redirect("Default.aspx");
        }

        this.LiteralErrorMessage.Text = string.Format(this.LiteralErrorMessage.Text, status);
        this.MultiViewPage.SetActiveView(this.ViewMessage);
    }

    protected void ButtonCancel_Click(object sender, EventArgs e) {
        Response.Redirect("Default.aspx");
    }

}
